/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * Licensed under Simplified BSD License
 *
 *
 * @Original Author: jin Chen
 * @date: Jan 19, 2005$
 * @version: 1.0
 */
package edu.psu.geovista.app.visualclassifier.classify.v2.gui;

import edu.psu.geovista.app.visualclassifier.classify.v2.LgToolTip;
import edu.psu.geovista.app.visualclassifier.classify.v2.colorpalette.v2.DynamicSwatchPaneImpl;
import edu.psu.geovista.classification.Category2D;
import edu.psu.geovista.classification.CategoryItf;
import edu.psu.geovista.classification.Range;

import javax.swing.*;
import java.awt.*;

public class LgToolTipPane extends JPanel{
    private DynamicSwatchPaneImpl xbarP=new DynamicSwatchPaneImpl(DynamicSwatchPaneImpl.create1DSampleColors(), SwingConstants.HORIZONTAL);
    private DynamicSwatchPaneImpl ybarP=new DynamicSwatchPaneImpl(DynamicSwatchPaneImpl.create1DSampleColors(), SwingConstants.VERTICAL );

 

    public static final java.awt.Color BACKGROUND_COLOR = new java.awt.Color(255, 255, 204);

    public LgToolTipPane() {
        xbarP.setGap(0,0);
        ybarP.setGap(0,0);
        this.xvPane =new CategoryValuePane();
        this.yvPane =new CategoryValuePane();

        initComponents();
        init();
    }

    /**
     * It
     * @param rowColors
     * @param columnColors
     * @param ctg
     */
    public void setTooltip(Color[] rowColors,Color[] columnColors,CategoryItf ctg){
          if(ctg instanceof Category2D){//2 dimension
              Category2D ctg2d=(Category2D) ctg ;
              String xvname = ctg2d.getXVariableName();
              String yvname = ctg2d.getYVariableName();
              if(xvname==null||xvname.trim().equals("") ){
                  xvname="Unknown X variable";
              }
              if(yvname==null||yvname.trim().equals("") ){
                  yvname="Unknown Y variable";
              }
              Range xrange = ctg2d.getXRange();
              Range yrange = ctg2d.getYRange();

              setCategoryPane((CategoryValuePane)xvPane,xvname,xrange);
              setCategoryPane((CategoryValuePane)yvPane,yvname,yrange);

              xbarP.setColors(rowColors);
              ybarP.setColors(columnColors);

              //arrangeLayout(LgToolTip.DISPLAY_TYPE_2D);
          }
          else{
              String xvname = ctg.getVariableName();
              Range xrange = ctg.getRange();
              setCategoryPane((CategoryValuePane)xvPane,xvname,xrange);
              xbarP.setColors(rowColors);
              //arrangeLayout(LgToolTip.DISPLAY_TYPE_1D);
          }
    }

    public  void arrangeLayout(int type){
        if (type ==LgToolTip.DISPLAY_TYPE_1D){
            this.BarPane.remove(ybarPane);
            this.VarPane.remove(yvPane);
            BarPane.setLayout(new java.awt.GridLayout(1, 1));
            VarPane.setLayout(new java.awt.GridLayout(1, 1));
        }
        else if(type==LgToolTip.DISPLAY_TYPE_2D){
             BarPane.setLayout(new java.awt.GridLayout(2, 1));
            VarPane.setLayout(new java.awt.GridLayout(2, 1));
            this.BarPane.add(ybarPane);
            this.VarPane.add(yvPane);
        }
        BarPane.revalidate();
        VarPane.revalidate();
        mainP.revalidate();
        mainP.repaint();

    }

    private static void setCategoryPane(CategoryValuePane p,String vname,Range vrange){
        p.setVarName(vname);
        p.setRange(vrange);

    }

    private void init(){
        xvPane.setBackground(BACKGROUND_COLOR);
        yvPane.setBackground(BACKGROUND_COLOR);
        xbarPane.setBackground(BACKGROUND_COLOR);
        ybarPane.setBackground(BACKGROUND_COLOR);

        jPanel2.setOpaque(false);
        jPanel3.setOpaque(false);
        jPanel5.setOpaque(false);
        jPanel1.setOpaque(false);

        mainP.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 153),1));
        /*mainP.setOpaque(false);
        this.setOpaque(false);*/

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        mainP = new javax.swing.JPanel();
        BarPane = new javax.swing.JPanel();
        xbarPane = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        xmidP = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        ybarPane = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        ymidP = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        VarPane = new javax.swing.JPanel();
        //xvPane = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        //yvPane = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();

        setLayout(new java.awt.BorderLayout());

        mainP.setLayout(new java.awt.GridBagLayout());

        BarPane.setLayout(new java.awt.GridLayout(2, 1));

        xbarPane.setLayout(new java.awt.GridLayout(3, 1));

        //xbarPane.setBorder(new javax.swing.border.EtchedBorder());
        xbarPane.add(jPanel1);

        xmidP.setLayout(new java.awt.BorderLayout());

        jLabel1.setText("xbar");
        //jLabel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0)));
        jLabel1.setPreferredSize(new java.awt.Dimension(22, 20));
        xmidP.add(jLabel1, java.awt.BorderLayout.CENTER);

        xbarPane.add(xbarP);

        xbarPane.add(jPanel5);

        BarPane.add(xbarPane);

        ybarPane.setLayout(new java.awt.GridLayout(1, 3));

        //ybarPane.setBorder(new javax.swing.border.EtchedBorder());
        ybarPane.add(jPanel2);

        ymidP.setLayout(new java.awt.BorderLayout());

        jLabel3.setText("ybar");
        //jLabel3.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0)));
        jLabel3.setPreferredSize(new java.awt.Dimension(20, 15));
        ymidP.add(jLabel3, java.awt.BorderLayout.CENTER);

        ybarPane.add(ybarP);

        ybarPane.add(jPanel3);

        BarPane.add(ybarPane);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.4;
        gridBagConstraints.weighty = 1.0;
        mainP.add(BarPane, gridBagConstraints);

        VarPane.setLayout(new java.awt.GridLayout(2, 1));


        VarPane.add(xvPane);



        VarPane.add(yvPane);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.6;
        gridBagConstraints.weighty = 1.0;
        mainP.add(VarPane, gridBagConstraints);

        add(mainP, java.awt.BorderLayout.CENTER);

    }


    // Variables declaration - do not modify
    private javax.swing.JPanel BarPane;
    private javax.swing.JPanel VarPane;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel mainP;
    private javax.swing.JPanel xbarPane;
    private javax.swing.JPanel xmidP;
    private javax.swing.JPanel xvPane;
    private javax.swing.JPanel ybarPane;
    private javax.swing.JPanel ymidP;
    private javax.swing.JPanel yvPane;
    // End of variables declaration

    
}
